package com.ruoyi.web.controller.environment;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.environment.domain.EnvThreeReport;
import com.ruoyi.environment.service.IEnvThreeReportService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 环保三同时资料Controller
 * 
 * @author yxf
 * @date 2021-08-10
 */
@RestController
@RequestMapping("/environment/material")
public class EnvThreeReportController extends BaseController
{
    @Autowired
    private IEnvThreeReportService envThreeReportService;

    /**
     * 查询环保三同时资料列表
     */
    @PreAuthorize("@ss.hasPermi('environment:material:list')")
    @GetMapping("/list")
    public TableDataInfo list(EnvThreeReport envThreeReport)
    {
        startPage();
        List<EnvThreeReport> list = envThreeReportService.selectEnvThreeReportList(envThreeReport);
        return getDataTable(list);
    }

    /**
     * 导出环保三同时资料列表
     */
    @PreAuthorize("@ss.hasPermi('environment:material:export')")
    @Log(title = "环保三同时资料", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(EnvThreeReport envThreeReport)
    {
        List<EnvThreeReport> list = envThreeReportService.selectEnvThreeReportList(envThreeReport);
        ExcelUtil<EnvThreeReport> util = new ExcelUtil<EnvThreeReport>(EnvThreeReport.class);
        return util.exportExcel(list, "环保三同时资料数据");
    }

    /**
     * 获取环保三同时资料详细信息
     */
    @PreAuthorize("@ss.hasPermi('environment:material:query')")
    @GetMapping(value = "/{etrId}")
    public AjaxResult getInfo(@PathVariable("etrId") Long etrId)
    {
        return AjaxResult.success(envThreeReportService.selectEnvThreeReportById(etrId));
    }

    /**
     * 新增环保三同时资料
     */
    @PreAuthorize("@ss.hasPermi('environment:material:add')")
    @Log(title = "环保三同时资料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EnvThreeReport envThreeReport)
    {
        return toAjax(envThreeReportService.insertEnvThreeReport(envThreeReport));
    }

    /**
     * 修改环保三同时资料
     */
    @PreAuthorize("@ss.hasPermi('environment:material:edit')")
    @Log(title = "环保三同时资料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EnvThreeReport envThreeReport)
    {
        return toAjax(envThreeReportService.updateEnvThreeReport(envThreeReport));
    }

    /**
     * 删除环保三同时资料
     */
    @PreAuthorize("@ss.hasPermi('environment:material:remove')")
    @Log(title = "环保三同时资料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{etrIds}")
    public AjaxResult remove(@PathVariable Long[] etrIds)
    {
        return toAjax(envThreeReportService.deleteEnvThreeReportByIds(etrIds));
    }
}
